
var class_num=location.search;
class_num=class_num.split('?')[1];
$('#href_list').attr('href','details_stu.html?'+class_num);
$('#href_course').attr('href','details_course.html?'+class_num);
if (islogin()) {
    $.post({
        url:"../requests/select_class_name.php",
        data:{'class_num':class_num},
        success:function (data) {
            if (data != 'none') {
                $('h1').text(data);
            }
        }
    });
    $.ajax({
        url:'../requests/show_details_stu.php',
        async:false,
        type:'POST',
        data:{'class_num':class_num},
        success:function (data) {
            if (data.length == 0) {
                $('.stu_list ul').append("<li>该班级没有学生</li>");
            }
            else {
                for (var i = 0; i < data.length; i++) {
                    var dom = "<li>" +
                        "<div class='hui-list-text'>" +
                        "<div class='hui-list-text-content'>" +
                        "<span class='stu_num'>" + data[i].num + "</span>" +
                        "<span class='stu_name'>" + data[i].name + "</span>" +
                        "</div>" +
                        "<div class='hui-list-info'>" +
                        "<input type='checkbox' name='stu_num' value='" + data[i].num + "'>" +
                        "</div>" +
                        "</div>" +
                        "</li>";
                    $('.stu_list ul').append(dom);
                }
            }
        }
    });
}
hui('#op').click(function(){
    meuns=['删除','添加'];
    hui.actionSheet(meuns,cancel,function (e) {
        if(e.index==0){
            var stu_nums=new Array();
            $("input[name='stu_num']:checked").each(function () {
                    stu_nums.push($(this).val());
            });
            if (stu_nums.length>0){
                $.post({
                    url:"../requests/delete_student.php",
                    data:{'stu_nums':stu_nums,'class_num':class_num},
                    success:function (data) {
                        if (data == '1') {
                             hui.iconToast('删除成功','success');
                            window.location.href="details_stu.html?"+class_num;
                        }
                        else {
                            hui.iconToast('有学生删除失败', 'warn');
                            window.location.href="details_stu.html?"+class_num;
                        }
                    }
                });
            }
            else hui.iconToast('未选择学生','warn');
        }
        if (e.index == 1) {
            window.location.href="add_stu.html?"+class_num;
        }
    })
    meuns=['个人中心','班级','文件','消息'];
});
